Add support (read) for MapAsia track files (.tr7).
authoroliskoli <oliskoli>
Fri, 15 Aug 2008 20:27:14 +0000 (20:27 +0000)
committeroliskoli <oliskoli>
Fri, 15 Aug 2008 20:27:14 +0000 (20:27 +0000)
Makefile.in
tr7.c [new file with mode: 0644]
vecs.c

index 90bfb9752cce91bc393951923d04c0ff1a71eda2..2bf3f766e7994a9da16111f5b78ba67848c86673 100644 (file)
@@ -59,7 +59,7 @@ ALL_FMTS=$(MINIMAL_FMTS) gtm.o gpsutil.o pcx.o cetus.o copilot.o \
        wbt-200.o stmsdf.o gtrnctr.o dmtlog.o raymarine.o alan.o vitovtt.o \
        ggv_log.o g7towin.o garmin_gpi.o lmx.o random.o xol.o dg-100.o \
        navilink.o mtk_logger.o ik3d.o osm.o destinator.o exif.o vidaone.o \
-       igo8.o gopal.o humminbird.o
+       igo8.o gopal.o humminbird.o tr7.o
 
 FMTS=@FMTS@
 
@@ -745,6 +745,8 @@ tpo.o: tpo.c defs.h config.h queue.h gbtypes.h zlib/zlib.h zlib/zconf.h \
   jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \
   jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \
   jeeps/gpsrqst.h jeeps/gpsinput.h jeeps/gpsproj.h
+tr7.o: tr7.c defs.h config.h queue.h gbtypes.h zlib/zlib.h \
+  zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h csv_util.h
 trackfilter.o: trackfilter.c defs.h config.h queue.h gbtypes.h \
   zlib/zlib.h zlib/zconf.h gbfile.h cet.h cet_util.h inifile.h \
   filterdefs.h strptime.h grtcirc.h
diff --git a/tr7.c b/tr7.c
new file mode 100644 (file)
index 0000000..99d4f97
--- /dev/null
+++ b/tr7.c
@@ -0,0 +1,121 @@
+/*
+
+    Support for MapAsia (.tr7) track file format.
+
+    Copyright (C) 2008 Olaf Klein, o.b.klein@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
+
+ */
+#include <ctype.h>
+#include <math.h>
+#include <string.h>
+#include <time.h>
+#include "defs.h"
+#include "jeeps/gpsmath.h"
+
+#define MYNAME "tr7"
+
+#define TR7_TRACK_MAGIC        0x223eadb
+
+static
+arglist_t tr7_args[] = {
+       ARG_TERMINATOR
+};
+
+static gbfile *fin;
+
+/*******************************************************************************
+* %%%        global callbacks called by gpsbabel main process              %%% *
+*******************************************************************************/
+
+static void
+tr7_rd_init(const char *fname)
+{
+       fin = gbfopen_le(fname, "rb", MYNAME);
+}
+
+static void 
+tr7_rd_deinit(void)
+{
+       gbfclose(fin);
+}
+
+static void
+tr7_read(void)
+{
+       unsigned char buff[32];
+       waypoint *wpt;
+       route_head *trk = NULL;
+       unsigned int magic;
+       
+       magic = gbfgetint32(fin);
+       if (magic != TR7_TRACK_MAGIC) {
+               fatal(MYNAME ": Invalid magic number in header (%X, but %X expected)!\n", magic, TR7_TRACK_MAGIC);
+       }
+
+       while (! gbfeof(fin)) {
+               gbfread(buff, 1, sizeof(buff), fin);
+               if (buff[0] == 0xD8) {
+                       struct tm tm;
+                       double lat, lon;
+
+                       lat = (double)le_read32(&buff[20]) / 1000000.0;
+                       lon = (double)le_read32(&buff[16]) / 1000000.0;
+                       if ((fabs(lat) > 90) || (fabs(lon) > 180)) continue;
+
+                       memset(&tm, 0, sizeof(tm));
+                       tm.tm_hour = buff[8];
+                       tm.tm_min = buff[10];
+                       tm.tm_sec = buff[12];
+
+                       wpt = waypt_new();
+
+                       wpt->latitude = lat;
+                       wpt->longitude = lon;
+                       wpt->creation_time = mkgmtime(&tm);
+
+                       if (! trk) {
+                               trk = route_head_alloc();
+                               track_add_head(trk);
+                       }
+                       track_add_wpt(trk, wpt);
+               }
+       }
+}
+
+/**************************************************************************/
+
+ff_vecs_t tr7_vecs = {         /* currently we can only read tracks */
+       ff_type_internal,
+       { 
+               ff_cap_none     /* waypoints */, 
+               ff_cap_read     /* tracks */, 
+               ff_cap_none     /* routes */
+       },
+       tr7_rd_init,    
+       NULL,
+       tr7_rd_deinit,  
+       NULL,
+       tr7_read,
+       NULL,
+       NULL,
+       tr7_args,
+       CET_CHARSET_ASCII, 0
+
+};
+
+/**************************************************************************/
diff --git a/vecs.c b/vecs.c
index 29e38f8ae232a331655a57cc525f70ed6ffc132c..f2e2db362477a2697f44a01753d9c6e257284afa 100644 (file)
--- a/vecs.c
+++ b/vecs.c
@@ -142,6 +142,7 @@ extern ff_vecs_t exif_vecs;
 extern ff_vecs_t vidaone_vecs;
 extern ff_vecs_t gopal_vecs;
 extern ff_vecs_t humminbird_vecs;
+extern ff_vecs_t tr7_vecs;
 
 static
 vecs_t vec_list[] = {
@@ -809,6 +810,12 @@ vecs_t vec_list[] = {
                "Humminbird waypoints (.hwr)",
                "hwr"
         },
+       {
+               &tr7_vecs,
+               "tr7",
+               "MapAsia track file (.tr7)",
+               "tr7"
+       },
 #endif // MAXIMAL_ENABLED
        {
                NULL,